<?php
require_once IA_ROOT . '/addons/unpor_baby/common/defines.php';

/**
 * Created by PhpStorm.
 * User: benhailong
 * Date: 2019/3/12
 * Time: 9:10 PM
 */

if (!(defined('IN_IA'))) {
    exit('Access Denied');
}

/**
 * UUID 生成工具
 */
function kit_uuid(){
    $chars = md5(uniqid(mt_rand(), true));
    $uuid = substr ( $chars, 0, 8 ) . '-'
        . substr ( $chars, 8, 4 ) . '-'
        . substr ( $chars, 12, 4 ) . '-'
        . substr ( $chars, 16, 4 ) . '-'
        . substr ( $chars, 20, 12 );
    return $uuid ;
}

/**
 * 返回 json 值
 * @param int $code
 * @param null $return
 */
function kit_show_json($code = 0, $msg = '')
{
    $ret = array('code' => $code, 'msg' => $msg);
    exit(json_encode($ret));
}

/**
 * 当图片上传成功的时候返回 json 值
 * @param int $status
 * @param string $msg
 * @param string $url
 */
function kit_show_img_json($status = 0, $msg = '', $url = '')
{
    $ret = array('status' => $status, 'msg' => $msg, 'url' =>$url);
    exit(json_encode($ret));
}

/**
 * 分页返回 json
 * @param int $code 状态码，一般返回0
 * @param string $msg 提示消息，可以为空
 * @param int $count 总条数
 * @param string $data 数据
 */
function kit_page_show_json($code = 0, $msg = '', $count = 0, $data = ''){
    $ret = array('code' => $code, 'msg' => $msg, 'count' => $count, 'data' => $data);
    exit(json_encode($ret));
}

/**
 * 删除空格，清楚文件中的空格和空字符串
 */
function kit_remove_null($str){
    $oldchar = array(" ","　","\t","\n","\r");
    $newchar = array("","","","","");
    return str_replace($oldchar,$newchar,$str);
}

/**
 * 控制弹窗
 * @param $_type 这里就是控制弹窗1.表示成功，0：表示失败，空则不弹窗, 其他值未定义
 * @param $_msg 这里是弹窗的提示消息
 * @return array
 */
function kit_alert($_type = 0, $_msg = '') {
    $_alert = array(
        '_type' => $_type,
        '_msg' => $_msg
    );
    return $_alert;
}